/**
 * 公共的工具类
 */
import Vue from 'vue';
import {Dialog, Toast} from 'vant';

Vue.use(Dialog);
Vue.use(Toast);

var common = {};

// 打开信息框(type=loading,fail,html,success)，2秒后自动关闭
common.toast = function (type, message, callback) {
    if (callback == null) {
        callback = function () {
        };
    }
    Toast({
        type: type,
        duration: 3000,
        message: message,
        forbidClick: true,
        onClose: callback
    });
};

// 打开确认框
common.dialog = function (message, confirm, cancel) {
    if (confirm == null) {
        confirm = function () {
        };
    }
    if (cancel == null) {
        cancel = function () {
        };
    }
    Dialog.confirm({
        title: '信息',
        message: message,
        messageAlign: 'left',
        showCancelButton: true,
    }).then(() => {
        confirm();
    }).catch(() => {
        // on cancel
        cancel();
    });
};


export default common;
